﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Async : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Page_PreRender(object sender, EventArgs e)
    {

    }

    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {

    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
string qq = this.TextBox1.Text;

cn.com.webxml.webservice.qqOnlineWebService service
    = new cn.com.webxml.webservice.qqOnlineWebService();

this.AddOnPreRenderCompleteAsync(

    (Object source, EventArgs args, AsyncCallback cb, Object extraData)
        =>
    {
        DateTime begin = DateTime.Now;
        this.Context.Items["Begin"] = begin;
        return service.BeginqqCheckOnline(qq, cb, service);
    },

    (IAsyncResult ar) =>
    {
        cn.com.webxml.webservice.qqOnlineWebService sourceService = ar.AsyncState
            as cn.com.webxml.webservice.qqOnlineWebService;
        string code = sourceService.EndqqCheckOnline(ar);

        DateTime begin = (DateTime)this.Context.Items["Begin"];
        DateTime end = DateTime.Now;
        TimeSpan span = end - begin;

        this.Label1.Text = QQOnlineHelper.GetOnlineStatus(code); ;
        this.Label2.Text = string.Format("请求共花费：{0} 毫秒。", span.TotalMilliseconds);
    }
);

    }
}